<template>
 <el-row v-loading="loading">
    <el-col :span="24">
      <tz-edit ref="tzEdit" v-on:save-finished="getTbodyList()"></tz-edit>
      <el-row class="search-row">
        <el-col :span="2">
            <el-button type="primary" icon="el-icon-plus" size="small"
            v-show="add"  style="float:left" @click="handleCreateTbody()">新增</el-button>
        </el-col>
        <el-col :span="5">
          <el-input placeholder="请输入查询的名字" size="small" v-model="likename">
          </el-input>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="24">
          <el-table :data="getTbodyList(likename).slice((pageNum-1)*pageSize,pageNum*pageSize)"  border size="mini" header-cell-class-name="header-row">
            <el-table-column prop="id" label="编号" header-align="center"></el-table-column>
            <el-table-column prop="tMember.fileNumber" label="档案号" header-align="center"></el-table-column>
            <el-table-column prop="tMember.name" label="姓名" header-align="center"></el-table-column>
            <el-table-column prop="createtime" label="评估日期" header-align="center" align="center"></el-table-column>
            <el-table-column prop="tQiAsthenia" label="气虚质" header-align="center" align="center" :formatter="formatreporttqiasthenia"></el-table-column>
            <el-table-column prop="tYangQuality" label="阳虚质" header-align="center" align="center" :formatter="formatreporttyangquality"></el-table-column>
            <el-table-column prop="tYinDeficiency" label="阴虚质" header-align="center" align="center" :formatter="formatreporttyindeficiency"></el-table-column>
            <el-table-column label="操作" header-align="center" align="center" width="200">
              <template slot-scope="scope">
                <!-- <el-button v-show="edit" type="primary" size="mini" class="el-icon-edit"
                  @click="handleEdittzcp(scope.row)">编辑</el-button> -->
                <el-button type="danger" size="mini"
                  @click="handleDeletetzcp(scope.row)" class="el-icon-delete">删除</el-button>
              </template>
            </el-table-column>
          </el-table>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="24">
          <el-pagination
            background
            @size-change="handleSizeChange"
            :current-page.sync="pageNum"
            :page-sizes="[2,4,6,8]"
            :page-size="pageSize"
            layout="total,sizes,prev,pager,next,jumper"
            :total="TbodyList.length">
          </el-pagination>
        </el-col>
      </el-row>
    </el-col>
  </el-row>
</template>

<script>
import {TbodyQuery,delType} from '@/api/tizhiceping_tj'
import TzEdit from '@/components/tzCeping/tzEdit'
export default {
  data() {
    return {
      loading:false,
      edit:true,
      add:true,
      TbodyList:[],
      pageSize:2,
      pageNum:1,
      likename:""
    }
  },
  methods: {
    handleSizeChange(val){
      this.pageSize = val;
      this.getTbodyList(likename)
      },
      getTbodyList(likename){
				return this.TbodyList.filter((item,i)=>{
						//包含 includes 的意思
						if(item.tMember.name.includes(likename)){
								return item;
						}
					})
    },
    async pageInit() {
      try {
        let [listTbodyResp] = await Promise.all([
         TbodyQuery()
        ])
        this.TbodyList = listTbodyResp.data
      } catch(error) {
        this.outputError(error)
      }
    },
    // handleEdittzcp(row){
    //   this.loading = true
    //   console.log(row.id)
    //   // PhysicalQueryByid(row.id)
    //   // .then(response => {
    //   //   this.$refs.tzEdit.$emit('openeditDialog',response.data)
    //   //   this.loading = false
    //   // })
    //   // .catch(error => {
    //   //   console.log(error)
    //   // })
    //   },
      handleDeletetzcp(row){
        console.log(row.createtime,row.tMemberId)
      this.$confirm('确定删除吗？', '提示', {
              confirmButtonText: '确定',
              cancelButtonText: '取消',
              type: 'warning'
            })
            .then(() => {
                this.loading = true
                delType(row.tMemberId,row.createtime).then(response => {
                this.loading = false
                this.pageInit();
              })
              .catch(error => {
                console.log(error)
              })
            })
            .catch(() => {})
        },
        handleCreateTbody(){
          this.$refs.tzEdit.$emit('openaddDialog')
          },
        formatreporttqiasthenia:function (row, column, cellValue) {
            if (cellValue===1){
                return '否';
            }else if (cellValue===0){
                return '是';
            }
        },
        formatreporttyangquality:function (row, column, cellValue) {
            if (cellValue===1){
                return '否';
            }else if (cellValue===0){
                return '是';
            }
        },
        formatreporttyindeficiency:function (row, column, cellValue) {
            if (cellValue===1){
                return '否';
            }else if (cellValue===0){
                return '是';
            }
        },
  },
  created() {
    this.pageInit()
  },
  components:{TzEdit}
}
</script>

<style>

</style>
